package org.dk.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import org.dk.domain.DataResult;
import org.dk.em.DataResultEnum;
import org.dk.pageInfo.PageInfo2;
import org.dk.pojo.TbBrand;
import org.dk.pojo.TbSpecification;
import org.dk.pojo.TbTypeTemplate;
import org.dk.service.BrandService;
import org.dk.service.TbSpecificationService;
import org.dk.service.TbTypeTemplateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("tbTypeTemplateController")
public class TbTypeTemplateController {

    @Reference
    private TbTypeTemplateService tbTypeTemplateService;
    @Reference
    private BrandService brandService;
    @Reference
    private TbSpecificationService tbSpecificationService;

    @RequestMapping("toTbTypeTemplateShow")
    public String ToTbTypeTemplateShow(){

        return "admin/type_template";
    }
    @RequestMapping("Show")
    public String Show(){

        return "admin/aaa";
    }

    @RequestMapping("gettbTypeTemplate")
    @ResponseBody
    public Map<Object, Object> GettbTypeTemplate(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                 @RequestParam(required = false, defaultValue = "5") Integer pageSize){
        PageInfo2<TbTypeTemplate> selevt = tbTypeTemplateService.select(pageNum,pageSize);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("total", selevt.getTotal());
        map.put("rows", selevt.getList());
        return map;
    }

    @RequestMapping("selectBrand")
    @ResponseBody
    public DataResult selectAll(){
        List<TbBrand> selevt = brandService.selevt();
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(selevt);
    }

    @RequestMapping("selectSpec")
    @ResponseBody
    public DataResult selectSpec(TbSpecification tbSpecification){
        List<TbSpecification> list =  tbSpecificationService.selectNull();
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(list);
    }

    @ResponseBody
    @RequestMapping("toAdd")
    public DataResult toAdd(TbTypeTemplate tbTypeTemplate){
        Boolean b = tbTypeTemplateService.insert(tbTypeTemplate);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(b);
    }

    @ResponseBody
    @RequestMapping("delete")
    public DataResult delete(Long id){
        Boolean b =tbTypeTemplateService.delete(id);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(b);
    }

    @ResponseBody
    @RequestMapping("updata")
    public DataResult updata(Long id){
        TbTypeTemplate tbTypeTemplate = tbTypeTemplateService.selectById(id);
        return DataResult.buildDataResult(DataResultEnum.SUCCESS).setData(tbTypeTemplate);
    }

    @RequestMapping("toupdata")
    @ResponseBody
    public Boolean toupdata(TbTypeTemplate tbTypeTemplate){
        Boolean b = tbTypeTemplateService.updata(tbTypeTemplate);
        return b;
    }
}
